<template>
  <div style="position: relative; height: 100%">
    <IFrame :src="amisUrl"  />
  </div>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { CommonStatusEnum } from '@/utils/constants'
import * as FormApi from '@/api/bpm/form'
import FcDesigner from '@form-create/designer'
import { encodeConf, encodeFields } from '@/utils/formCreate'
import { useTagsViewStore } from '@/store/modules/tagsView'
import { useFormCreateDesigner } from '@/components/FormCreate'
import { DsgnFormService } from '@/api/res/approval/DsgnFormService'
import { ref } from 'vue'

const { result_code, base_url, request_timeout } = config
import { useApprovalDesignerStore } from '@/store/modules/dsgn/ApprovalDesigner'
import { VxeUI } from 'vxe-pc-ui'
import JsonEditor from 'vue3-ts-jsoneditor'
// import EfInputRule from "@/components/FormCreate/src/sn/EfInputRule";
import {useFormDesignerStore} from "@/store/modules/formDesigner/FormDesignerStore";
import {config} from "@/config/axios/config";

defineOptions({ name: 'AmisDesigner' })




const designerStore = useApprovalDesignerStore()

if (!designerStore.designerModel.form || Object.keys(designerStore.designerModel).length === 0) {
  // 设置默认值
  designerStore.designerModel = {
    form: {
      configJson: '{}' // 假设默认值是一个空的 JSON 字符串
      // 其他默认属性...
    }
  }
}
const configJson = ref(designerStore.getDsgnModelFormConfigJson)
const amisUrl=ref(import.meta.env.VITE_BASE_URL+'/pages/index.html#/edit/'+designerStore.designerModel.basic.resId)
debugger
/** 初始化 **/
onBeforeUpdate(async () => {
  // // 场景一：新增表单
  // const id = query.id as unknown as number
  // if (!id) {
  //   return
  // }
  // // 场景二：修改表单
  // const data = await FormApi.getForm(id)
  // const data = await FormApi.getForm('1893925754010464257')

  // formData.value = data
  // setConfAndFields(designer, configJson.formConfig, data.formConfig)
  const config = designerStore.getDsgnModelFormConfigJson
  // designer.value?.addComponent(EfInputRule)
  if (config.formConfig) {
    // designer.value.setOption(config.formConfig)
    // designer.value.setRule(config.widgetList)
    // setFormJson(config.widgetList)
  }
})

// 实现 DsgnFormService 接口
const dsgnFormService: DsgnFormService = {
  getFormData: () => {
    // const formData = designer.value.getOption()
    // return formData
  },
  getFormConfig: () => {
    // const formConfig = designer.value.getOption()
    // // const config = encodeConf(designer)
    // // const fields = encodeFields(designer)
    // const widgetList = designer.value.getRule()
    // return {
    //   widgetList: widgetList,
    //   formConfig: formConfig
    // }
  }
}

defineExpose({
  dsgnFormService
})
</script>

<style lang="scss">
@import '@/styles/FormCreate/customFormCreateDesigner';

.importHandle {
  display: flex;
  align-items: center;
  margin-right: 15px;
}
</style>
